<?php
include "./library.php";
$query1 = "select * from carpool.tripinfo where origin = '".trim($_POST[from])."'";
$query2 = "select * from carpool.tripinfo where dest = '".trim($_POST[To])."'";
$query3 = "select * from carpool.tripinfo where origin = '".trim($_POST[from])."' and dest = '".trim($_POST[To])."'";

if($_POST[from] && $_POST[To]){;
	$result = pg_query($query3);
} else if(!$_POST[from] && $_POST[To]){
	$result = pg_query(query2);
} else if($_POST[from] && !$_POST[To]){
	$result = pg_query(query1);
}
$arr = pg_fetch_all($result);
$cnt = count($arr);
$crt_time = date('Y-m-d H:i:s');
for ($i = 0; $i < $cnt; $i++){
	if($arr[$i][depart_time] > $crt_time){
		$posting  = "START: ". $arr[$i][origin] . "\t" . "END: ". $arr[$i][dest] . "\t" . $arr[$i][depart_time];
		 print "<a href='./index.php'>$posting</a><br>";
	}

}
?>